package com.example.baseballgame;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

public class RuleActivity extends Activity {

	private int tag = 1;
	private MyDbHelper helper;
	Cursor cursor;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_baseball_rule);
		ImageView iv = (ImageView)findViewById(R.id.imageview);
		helper = new MyDbHelper(this, "baseballgameDB.sqlite", null, 1);
		
		Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.ruletext);
		iv.setScaleType(ImageView.ScaleType.FIT_START);
	}
	
	@Override
	protected void onStop() {
		if(cursor != null && !cursor.isClosed()){
			cursor.close();
		}
		
		super.onStop();
	}
	
	public void doAction(View view){
		tag = Integer.parseInt(view.getTag().toString());
		Intent intent = new Intent(RuleActivity.this, PlayActivity.class);
		
		if(tag == 1){
			intent.putExtra("numrule", "3");
		}else if(tag == 2){
			intent.putExtra("numrule", "4");
		}else{
			SQLiteDatabase db = helper.getReadableDatabase();
			cursor = db.rawQuery("SELECT id, score FROM baseballgame", null);
			
			//Toast.makeText(this, "데이터가 없습니다.", Toast.LENGTH_SHORT).show();
			intent = new Intent(RuleActivity.this, ScoreActivity.class);	
		}
		startActivity(intent);
	}
}
